<%--
  Created by IntelliJ IDEA.
  User: a479655315
  Date: 2019/9/2
  Time: 11:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link rel="icon" type="image/png"
          href="img/favicon.ico">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <title>用户列表</title>

    <meta
            content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'
            name='viewport' />
    <meta name="viewport" content="width=device-width" />

    <!-- Bootstrap core CSS     -->
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css"
          rel="stylesheet" />

    <!-- Animation library for notifications   -->
    <link href="${pageContext.request.contextPath}/css/animate.min.css"
          rel="stylesheet" />

    <!--  Light Bootstrap Table core CSS    -->
    <link
            href="${pageContext.request.contextPath}/css/light-bootstrap-dashboard.css"
            rel="stylesheet" />


    <!--  CSS for Demo Purpose, don't include it in your project     -->
    <link href="${pageContext.request.contextPath}/css/demo.css"
          rel="stylesheet" />


    <!--     Fonts and icons     -->

    <link href="${pageContext.request.contextPath}/css/pe-icon-7-stroke.css"
          rel="stylesheet" />
    <script>
        //删除用户
        function delUser(id) {
            if(confirm("确认删除该用户？")){
                $.ajax({
                    url: '${pageContext.request.contextPath}/user/delUser.html',
                    dataType: 'text',
                    type: 'get',
                    data: {
                        id: id
                    },
                    success: function (res) {
                        if(res == "ok"){
                            window.location.reload()
                        }
                        if(res == "no"){
                            alert("删除失败！该用户发表过新闻！")
                        }
                    }

                })
            }
        }

    </script>


</head>
<body>

<div class="wrapper">




    <!-- 左侧导航 -->
    <%@include file="include/left.jsp" %>

    <div class="main-panel">

        <!-- nav -->
        <%@include file="include/nav.jsp" %>



        <div class="content">
            <div class="container-fluid">
                <div class="row">

                    <div class="col-md-12">
                        <div class="card">
                            <div class="header">
                                <h4 class="title">用户管理</h4>
                                <p class="category">Here is a subtitle for this table</p>
                                <form action="${pageContext.request.contextPath}/user/findAllUsers.html" method="get">
                                    <div style="float:left; margin:0 2px; width: 130px;">
                                        <input type="text" name="searchUsername" class="form-control" placeholder="查询用户名" size=10  value="${pageInfo.searchUsername}">
                                    </div>
                                    <div style="float:left; margin:0 2px; width: 65px;">
                                        <button type="submit"  class="btn btn-info btn-fill pull-right">查询</button>
                                    </div>
                                    <div style="float:left; margin:0 2px; width: 65px;">
                                        <button type="button"   onclick="window.location.href='${pageContext.request.contextPath}/user/addUserPage.html'"   class="btn btn-info btn-fill pull-right">添加</button>
                                    </div>
                                </form>

                            </div>
                            <div class="content table-responsive table-full-width">
                                <table class="table table-hover table-striped">
                                    <thead>
                                    <th>序号</th>
                                    <th>用户名</th>
                                    <th>性别</th>
                                    <th>权限</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                    <th>操作</th>

                                    </thead>
                                    <tbody>
                                    <c:forEach items="${pageInfo.list}" var="user" varStatus="vs">
                                        <tr  height="35px">
                                            <td>${vs.count}</td>
                                            <td>${user.username}</td>
                                            <td>${user.sex}</td>
                                            <td>${user.power==0?"普通管理员":"超级管理员"}</td>
                                            <td><fmt:formatDate value="${user.createtime}" pattern="yyyy-MM-dd"/></td>
                                            <td style="font-size: 12px"><a
                                                    href="${pageContext.request.contextPath}/user/updatePage.html?pageNum=${pageInfo.pageNum}&id=${user.id}&searchUsername=${pageInfo.searchUsername}">修改</a></td>
                                            <td style="font-size: 12px"><a
                                                    href="javascript:void(0)" onclick="delUser(${user.id})">删除</a></td>
                                        </tr>

                                    </c:forEach>
                                    </tbody>
                                </table>

                            </div>
                            <div style=" margin: 0 0 0px 50px;padding:0 0 20px 0; width: 70%;">

                                <c:if test="${pageInfo.hasPreviousPage}">
                                    <a href="${pageContext.request.contextPath}/user/findAllUsers.html?pageNum=1&searchUsername=${pageInfo.searchUsername}">【首页】 </a>
                                    <a href="${pageContext.request.contextPath}/user/findAllUsers.html?pageNum=${pageInfo.pageNum - 1}&searchUsername=${pageInfo.searchUsername}">【上一页】 </a>
                                </c:if>

                                <c:forEach items="${pageInfo.navigatepageNums}" var="i">
                                    <c:if test="${i == pageInfo.pageNum}"><font color="red">【${i}】</font></c:if>
                                    <c:if test="${i != pageInfo.pageNum}">
                                        <a href="${pageContext.request.contextPath}/user/findAllUsers.html?pageNum=${i}&searchUsername=${pageInfo.searchUsername}">【${i}】 </a>
                                    </c:if>
                                </c:forEach>

                                <c:if test="${pageInfo.hasNextPage}">
                                    <a href="${pageContext.request.contextPath}/user/findAllUsers.html?pageNum=${pageInfo.pageNum + 1}&searchUsername=${pageInfo.searchUsername}">【下一页】 </a>
                                    <a href="${pageContext.request.contextPath}/user/findAllUsers.html?pageNum=${pageInfo.pages}&searchUsername=${pageInfo.searchUsername}">【末页】 </a>
                                </c:if>

                            </div>

                            <form action="${pageContext.request.contextPath}/user/findAllUsers.html" method="post">
                                <input type="hidden" value="${pageInfo.searchUsername}" name="searchUsername">
                                <div style=" float: right; margin:-50px 80px 0 0; width: 60px; height: 40px">
                                    <input type="number" max="${pageInfo.pages}" min="1" id="skipNum" class="form-control" placeholder="页面" size=2  name="pageNum"  value="${pageInfo.pageNum}">
                                </div>
                                <div style="float: right; margin:-50px 10px 0 0; width: 60px; height: 40px">
                                    <button type="submit" id="skipBut"  class="btn btn-info btn-fill pull-right">跳转</button>
                                </div>
                            </form>


                        </div>
                    </div>

                </div>

                <%@include file="include/footer.jsp" %>
            </div>
        </div>
    </div>
</div>


</body>

<!--   Core JS Files   -->
<script src="${pageContext.request.contextPath}/js/jquery-1.10.2.js"
        type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"
        type="text/javascript"></script>

<!--  Checkbox, Radio & Switch Plugins -->
<script
        src="${pageContext.request.contextPath}/js/bootstrap-checkbox-radio-switch.js"></script>

<!--  Charts Plugin -->
<script src="${pageContext.request.contextPath}/js/chartist.min.js"></script>

<!--  Notifications Plugin    -->
<script src="${pageContext.request.contextPath}/js/bootstrap-notify.js"></script>


<!-- Light Bootstrap Table Core javascript and methods for Demo purpose -->
<script
        src="${pageContext.request.contextPath}/js/light-bootstrap-dashboard.js"></script>

<!-- Light Bootstrap Table DEMO methods, don't include it in your project! -->
<script src="${pageContext.request.contextPath}/js/demo.js"></script>


</html>
